<?php
$width = '';
$height = '';
if(!empty($_POST)){

$long = !empty($_POST['long']) ? floatval($_POST['long']) : 0 ;
$width = !empty($_POST['width']) ? floatval($_POST['width']) : 0 ;

$zhouchang = ( $long + $width ) * 2 ;


}

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="textml; charset=GB2312" />
<title>计算矩形</title>
</head>

<body>
<form action="" method="POST">
<h3>计算矩形周长</h3>
<p>长：<input type="text" name="long" id="long" value="<?php echo $long; ?>" /></p>
<p>宽：<input type="text" name="width" id="width" value="<?php echo $width; ?>" /></p>
<?php if(!empty($_POST)){ ?>
<p>周长：<?php echo $zhouchang; ?> </p>
<?php } ?>
<p><input type="submit" name="smt" value="计算" /></p>

</form>
</body>
